﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RulesEngine.Rule
{
    public abstract class ThresholdRule : BaseRule
    {
        private String filed;

        private State preState = State.Common;
        private State currentState = State.Common;

          

        private void stateRunning()
        {
            //前置状态是Common的时候，判断是否触发规则
            if (this.preState == State.Common && chargeState(State.Triggerd))
            {
                onTrigger();
                this.preState = State.Triggerd;
                this.currentState = State.Warning;
            }
            //前置状态是Warning的时候，判断是恢复规则
            else if (this.preState == State.Warning && chargeState(State.Recovered))
            {
                onRecovery();
                this.preState = State.Recovered;
                this.currentState = State.Common;
            }
            this.preState = this.currentState;
        }

        public override void run()
        {
            this.stateRunning();
        }


    }
}
